package com.jscm.openselect;

import com.jscm.showdata.SelectDataView;
import com.jscm.showdata.TagMomeory;
import com.scm.all.export.ByteUtils;
import com.scm.all.export.SystemUtils;
import com.scm.all.export.WindowOperationUtils;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import org.apache.commons.lang3.StringUtils;

import java.util.Iterator;

/**
 * 首次搜索
 */
public class SelecthBoxSearchBtnFilter {
    public static Button button = new Button();
    static {
        init();
    }

    private static void init() {
        button.setPrefWidth(80);
        button.setPrefHeight(40);
        button.setText("过滤列表");
        button.setId("SelectBtn");
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                SelecthBoxSearchBtnListAddress.flag=false;
                SelecthBoxSearchBtnListAddress.button.setText("开始列表刷新");
                if(SelectOptionCheckBoxOffset.checkBox.isSelected() && SelectTableView.observableList.size()>0){
                    ObservableList<TagMomeory> observableList = FXCollections.observableArrayList();
                    observableList.clear();
//                    偏移列表的值
                    for (int i =0;i<SelectTableView.observableList.size();i++){
//                        数据列表的值
                        for(int j = 0;j<SelectDataView.observableList.size();j++){
                            if(StringUtils.equals(SelectTableView.observableList.get(i),SelectDataView.observableList.get(j).getBaseAddress())){
                                TagMomeory tagMomeory = new TagMomeory(SelectDataView.observableList.get(j).getIsStatic(),SelectDataView.observableList.get(j).getHexData().toUpperCase(),SelectDataView.observableList.get(j).getUpdateValue(),SelectDataView.observableList.get(j).getBaseAddress(),SelectDataView.observableList.get(j).getTypeData(),SelectDataView.observableList.get(j).getLen());
                                observableList.add(tagMomeory);
                            }
                        }
                    }
                    SelectDataView.observableList = observableList;
                    SelectDataView.tableView.setItems(SelectDataView.observableList);
                }else {
                    SystemUtils.messageBoxExW(WindowOperationUtils.windowGetHwnd(),"请先确认是否添加偏移和勾选筛选偏移","温馨提示",0);
                }

            }
        });
    }
}
